// cron 0 10 * * *  滨江抢购.js
const cookie = `` //CK填这
//https://service.jifenfu.net/sspmarketingactivity-service/client headers中的COOKIE
///下面是话费的
const goodsJSON = {
  "goodsGroupDTOS": [
    {
      "freight": 0,
      "serviceCode": "wnkq",
      "goodsPrice": 0,
      "skuDTOS": [
        {
          "activityPrice": "0",
          "ifLimitArea": 0,
          "priceShowTypeSnapshot": "{\"goodsPriceShowType\":1,\"cashAmount\":null,\"points\":2000}",
          "salePrice": 1000,
          "ifDeductBenefitCard": 0,
          "num": 1,
          "points": "2000",
          "isActivity": 1,
          "preSalePostDate": "",
          "marketingActivityId": "1696823088530808833",
          "preSalePostDelayDays": "",
          "ifActivityPriceThreshold": 0,
          "skuListPicUrl": "//ossimage.jifenfu.net/erpadmin/default/20210525/f7ce2a83-23d9-4cb2-bbff-8a20bbe6b0d2.jpg",
          "specSnapshot": "[{\"specId\":\"7069\",\"specName\":\"规格\",\"specValueId\":\"1005\",\"specValue\":\"10元\"}]",
          "ifErpPriceType": 0,
          "commonDisplayExtData": {
            "errCodeMsg": []
          },
          "skuMarketPrice": "1000",
          "inventory": 10,
          "useDescription": "//ossimage.jifenfu.net/erpadmin/default/20210929/aa287693-d020-4f09-8161-9c871d87d6bb.html",
          "cashAmount": 1000,
          "spuId": "7069",
          "serviceCode": "wnkq",
          "skuStatus": 1,
          "preSaleType": "",
          "skuName": "京东E卡10元",
          "ifServerCard": null,
          "marketingActivityGoodsId": "1696823088648249345",
          "goodsExtJson": [],
          "skuId": "AGA0100A0IA",
          "goodsDisplayExtJson": {},
          "goodsPriceType": 1,
          "goodsPriceShowDTO": {
            "points": 2000,
            "cashAmount": null,
            "goodsPriceShowType": 1
          },
          "activityPriceThreshold": 0
        }
      ]
    }
  ],
  "ifDeductPoints": 1,
  "totalPrice": 0,
  "marketingActivityGoodsId": "1696823088648249345",
  "skuOrderUserInfoDTO": [],
  "marketingActivityId": "1696823088530808833",
  "num": 1,
  "priceDetailDTOS": [
    {
      "points": 2000,
      "priceValue": 1000,
      "priceType": 2
    },
    {
      "points": 0,
      "priceValue": 0,
      "priceType": 1
    }
  ]
};

//https://service.jifenfu.net/sspmarketingactivity-service/client/marketing/order/activity/create 抢购链接中BODY  抢哪个就抓哪个

//获取COOKIE接口 
//user = WOOLWEB获取的USER
//name 获取的name
//phone手机号
           /* let options = {
                method:`GET`,
                url: `https://service.jifenfu.net/sspmall-service/client/channel/mall/entry/scene/5fe79d396893452c?user=65070&name=APP%E7%94%A8%E6%88%B784235&phone=18730978625&tenant=bjq&head=`,
                headers:
                {
                    "Host": "service.jifenfu.net",
                    "upgrade-insecure-requests": "1",
                    "user-agent": "Mozilla/5.0 (Linux; Android 10; MI 8 Lite Build/QKQ1.190910.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/81.0.4044.138 Mobile Safari/537.36",
                    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9",
                    "x-requested-with": "com.hzyapp.binjiang",
                    "sec-fetch-site": "none",
                    "sec-fetch-mode": "navigate",
                    "sec-fetch-user": "?1",
                    "sec-fetch-dest": "document",
                    "accept-encoding": "gzip, deflate",
                    "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7"
                }

            }*/

            //返回headers中有set-cookie 但是我测试不成功 小黄鸟重发成功

function sm3(data) {
    const crypto = require('crypto');
    const buffer = Buffer.from(data, 'utf8');

    // 创建哈希对象
    const hash = crypto.createHash('SM3');
    // 更新哈希对象
    hash.update(buffer);
    // 计算哈希值  
    const result = hash.digest('hex');
    return result;
}
function newNonce() {
    var result = '';
    var characters = '0123456789';
    var charactersLength = characters.length;
    for (var i = 0; i < 16; i++) {
        result += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    return result;
}
function newTimestamp() {
    var date = new Date(); // 月份是从0开始计数的，所以11表示12月
    date.setHours(date.getHours() + 8); // 增加8小时以获取中国时间
    var formattedDate = date.toISOString().slice(0, 23); // 获取ISO格式的日期时间字符串，并截取到毫秒部分
    return formattedDate;
}

let nonce = newNonce()
let timestamp = newTimestamp()
let bodyJson = { "ifDeductPoints": 1, "marketingActivityGoodsId": "1715189450205192194", "marketingActivityId": "1715189449626378242", "num": 1, "priceDetailDTOS": [{ "points": 1000, "priceType": 2, "priceValue": 500 }, { "points": 0, "priceType": 1, "priceValue": 0 }], "goodsGroupDTOS": [{ "freight": 0, "goodsPrice": 0, "serviceCode": "wnkq", "skuDTOS": [{ "num": 1, "serviceCode": "wnkq", "skuId": "ABE0300205B", "skuMarketPrice": "700", "salePrice": 700, "skuListPicUrl": "//ossimage.jifenfu.net/erpadmin/default/20211222/09399ed3-6906-40d7-a51f-201db36151f2.png", "skuName": "网易云音乐黑胶VIP周卡", "preSaleType": "", "preSalePostDelayDays": "", "preSalePostDate": "", "goodsPriceType": 1, "points": "1000", "cashAmount": 700, "skuStatus": 1, "specSnapshot": "[{\"specId\":\"7226\",\"specName\":\"规格\",\"specValueId\":\"9991\",\"specValue\":\"周卡\"}]", "spuId": "7226", "inventory": 10, "goodsPriceShowDTO": { "goodsPriceShowType": 1, "cashAmount": null, "points": 1400 }, "ifServerCard": null, "ifDeductBenefitCard": 0, "ifErpPriceType": 0, "useDescription": "//ossimage.jifenfu.net/erpadmin/default/20211221/d15281ab-7eb8-4c4a-9479-b61004842870.html", "isActivity": 1, "marketingActivityGoodsId": "1715189450205192194", "marketingActivityId": "1715189449626378242", "activityPrice": "0", "goodsExtJson": [], "activityPriceThreshold": 0, "ifActivityPriceThreshold": 0, "ifLimitArea": 0, "commonDisplayExtData": { "errCodeMsg": [{ "code": "10546", "scene": "活动未开始", "msg": "活动暂未开始~" }, { "code": "10547", "scene": "活动已结束", "msg": "活动已结束啦~" }, { "code": "10519", "scene": "当前时间未再活动开放时间内", "msg": "当前时间未在活动时间内" }, { "code": "10548", "scene": "非指定参与地区", "msg": "仅限指定地区可参与" }, { "code": "10531", "scene": "当前时间不在分时段内", "msg": "当前不在可购时段，请稍后再来" }, { "code": "10561", "scene": "活动不支持抵用券抵扣", "msg": "活动不支持抵用券抵扣" }, { "code": "10544", "scene": "已存在未支付的活动订单", "msg": "存在未支付的活动订单,请先完成支付" }, { "code": "10527", "scene": "超过活动库存限制", "msg": "来晚了~商品已抢完" }, { "code": "10533", "scene": "超过商品周期限制", "msg": "本期活动商品已抢完，下次请早哦" }, { "code": "10532", "scene": "超过商品库存限制", "msg": "很遗憾，该商品已抢完" }, { "code": "10534", "scene": "超过每人周期限制", "msg": "当前可购数量已达上限～敬请谅解" }, { "code": "10570", "scene": "超过商品每人周期限制", "msg": "当前可购数量已达上限～敬请谅解" }, { "code": "10535", "scene": "未预约客户不可参与", "msg": "仅限预约客户参与哦~" }, { "code": "10524", "scene": "超过活动人群限制额度", "msg": "本次支付超过活动限制额度" }, { "code": "11026", "scene": "用户余额不足", "msg": "用户余额不足" }, { "code": "10520", "scene": "收货地址不在活动范围内", "msg": "您的收货地址不在活动范围内" }, { "code": "10518", "scene": "活动分组规则达到上限", "msg": "当前可购数量已达上限～敬请谅解" }] }, "goodsDisplayExtJson": {}, "priceShowTypeSnapshot": "{\"goodsPriceShowType\":1,\"cashAmount\":null,\"points\":1400}" }] }], "totalPrice": 0, "skuOrderUserInfoDTO": [] }
let sign = sm3(JSON.stringify(goodsJSON) + nonce + timestamp)
let options = {
    method: `POST`,
    url: `https://service.jifenfu.net/sspmarketingactivity-service/client/marketing/order/activity/create`,
    headers:
    {
        "Host": "service.jifenfu.net",
        "accept": "application/json, text/plain, */*",
        "timestamp": timestamp,
        "nonce": nonce,
        "user-agent": "Mozilla/5.0 (Linux; Android 10; MI 8 Lite Build/QKQ1.190910.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/81.0.4044.138 Mobile Safari/537.36",
        "sign": sign,
        "Content-Type": "application/json;charset=UTF-8",
        "origin": "https://service.jifenfu.net",
        "x-requested-with": "com.hzyapp.binjiang",
        "sec-fetch-site": "same-origin",
        "sec-fetch-mode": "cors",
        "sec-fetch-dest": "empty",
        "referer": "https://service.jifenfu.net/sspmall-front/index.html",
        "accept-encoding": "gzip, deflate",
        "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
        "cookie": cookie
    },
    data: JSON.stringify(goodsJSON)
}

var axios = require("axios").default;


axios.request(options).then(function (response) {
    console.log(response.data);
}).catch(function (error) {
    console.error(error);
});